package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.DataSource;
import com.zygh.interactiveplatform.module.entity.DataSource;
import com.zygh.interactiveplatform.module.service.DataSourceService;
import com.zygh.interactiveplatform.module.service.DataSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/data-source")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_DATASOURCE})
public class DataSourceController {
    @Resource
    private DataSourceService dataSourceService;

    @ApiOperation(value = "数据来源新增", notes = "数据来源新增")
    @PostMapping("addDataSourcee")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_DATASOURCE, content = "数据来源新增")
    public ResponseDTO addDataSourcee(@RequestBody @Valid DataSource dataSource) {
        return dataSourceService.addDataSource(dataSource);
    }
    @ApiOperation(value = "数据来源修改", notes = "数据来源修改")
    @PostMapping("updateDataSource")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_DATASOURCE, content = "数据来源修改")
    public ResponseDTO updateDataSource(@RequestBody @Valid DataSource dataSource) {
        return dataSourceService.updateDataSource(dataSource);
    }
    @ApiOperation(value = "数据来源删除", notes = "数据来源删除")
    @PostMapping("deleteDataSource")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_DATASOURCE, content = "数据来源删除")
    public ResponseDTO deleteDataSource(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return dataSourceService.deleteDataSource(new_id);
    }
    @ApiOperation(value = "查询所有数据来源", notes = "查询所有数据来源")
    @GetMapping("findDataSourceAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_DATASOURCE, content = "查询所有数据来源")
    public ResponseDTO findDataSourceAll(Integer current, Integer size) {
        return dataSourceService.findDataSourceAll(current,size);
    }
}
